﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace _02.建造者模式
{
    /// <summary>
    /// 领域实体基类
    /// </summary>
    public abstract class BaseEntity
    {
        #region 00.构造器
        /// <summary>
        /// 构造器
        /// </summary>
        protected BaseEntity()
        {
            this.Id = Guid.NewGuid();
            this.Deleted = false;
            this.AddedTime = DateTime.Now;
            this.SavedTime = DateTime.Now;
            this.DeletedTime = null;
        }
        #endregion

        #region 01.主键 —— Guid Id
        /// <summary>
        /// 主键
        /// </summary>
        [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
        public Guid Id { get; protected set; }
        #endregion

        #region 02.软删除标记 —— bool Deleted
        /// <summary>
        /// 软删除标记
        /// </summary>
        [Required]
        public bool Deleted { get; set; }
        #endregion

        #region 03.添加时间 —— DateTime AddedTime
        /// <summary>
        /// 添加时间
        /// </summary>
        [Required]
        public DateTime AddedTime { get; protected set; }
        #endregion

        #region 04.保存时间 —— DateTime SavedTime
        /// <summary>
        /// 保存时间
        /// </summary>
        [Required]
        public DateTime SavedTime { get; set; }
        #endregion

        #region 05.删除时间 —— Nullable<DateTime> DeletedTime
        /// <summary>
        /// 删除时间
        /// </summary>
        public DateTime? DeletedTime { get; set; }
        #endregion
    }
}
